package cn.iune.web.erp.controllers;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.itextpdf.text.Document;
import com.itextpdf.text.pdf.PdfWriter;
import com.justep.baas.Utils;

import cn.iune.config.SecurityService;
import cn.iune.erp.inventory.FileItem;
import cn.iune.erp.inventory.IFileGroupService;
import cn.iune.erp.inventory.IFileItemService;
import cn.iune.erp.inventory.IFileStorageService;
import cn.iune.erp.inventory.IInventoryService;
import cn.iune.erp.inventory.IItemBatchService;
import cn.iune.erp.inventory.IStocktakingDetailService;
import cn.iune.erp.inventory.IStocktakingService;
import cn.iune.erp.inventory.IStorageItemBatchService;
import cn.iune.erp.inventory.IStorageItemService;
import cn.iune.erp.inventory.IStorageLedgerService;
import cn.iune.erp.inventory.IStorageRecordDetailService;
import cn.iune.erp.inventory.IStorageRecordService;




@Controller
@RequestMapping(value="/inventory")
public class InventoryController {
	
	@Autowired
	private IFileStorageService fileStorageService;
	@Autowired
	private IFileItemService fileItemService;

	
	
	@Autowired
	private IStorageRecordService storageRecordService;
	@Autowired
	private IStorageRecordDetailService storageRecordDetailService;
	@Autowired
	private IStorageItemService storageItemService;
	@Autowired
	private IStorageItemBatchService storageItemBatchService;
	@Autowired
	private IItemBatchService itemBatchService;
	
	@Autowired
	private IFileGroupService fileGroupService;
	
	@Autowired
	private IStocktakingService stocktakingService;
	
	@Autowired
	private IStocktakingDetailService stocktakingDetailService;
	
	
	@Autowired
	private IInventoryService inventoryService;
	
	@Autowired
	private IStorageLedgerService storageLedgerService;
	

	
	
	

	
	/*
	@RequestMapping(value="/fileStorage/list",method=RequestMethod.GET)
	public ModelAndView fileStorageList(){
		ModelAndView mav = new ModelAndView("/inventory/fileStorage/list");
		return mav;
	}

	@RequestMapping(value="/fileStorage/single",method=RequestMethod.GET)
	public ModelAndView fileStorageSingle(){
	
		ModelAndView mav = new ModelAndView("/inventory/fileStorage/single");
		return mav;
	}
	*/
	
	@RequestMapping(value="/fileStorage/tree",method=RequestMethod.GET)
	public ModelAndView fileStorageTree(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileStorage/tree");
		return mav;
	}
	
	@RequestMapping(value="/fileStorage/sortView",method=RequestMethod.GET)
	public ModelAndView fileStorageSortView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileStorage/sort");
		return mav;
	}
	//重新排序
	@RequestMapping(value = "/fileStorage/sort", method = RequestMethod.POST)
	@ResponseBody
	public void fileStorageSort(@RequestBody JSONObject data){
		String parentID = data.getString("parentID");
		JSONArray jsonArray =  data.getJSONArray("ids");
//		System.out.println("jsonArray-->"+jsonArray);
		List<String> ids = new ArrayList<String>();
		for(int i=0; i<jsonArray.size();i++){
			ids.add(jsonArray.getString(i));
		}
//		System.out.println("ids-->"+ids);
		fileStorageService.sort(parentID, ids);
	}
	
	
	//移动
	@RequestMapping(value="/fileStorage/moveView",method=RequestMethod.GET)
	public ModelAndView fileStorageMoveView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileStorage/move");
		return mav;
	}
	//移动
	@RequestMapping(value = "/fileStorage/move", method = RequestMethod.POST)
	@ResponseBody
	public void fileStorageMove(@RequestBody JSONObject data){
		String rowID = data.getString("rowID");
		String oldParentID = data.getString("oldParentID");
		String newParentID = data.getString("newParentID");
		fileStorageService.move(rowID, oldParentID, newParentID);
	}

	@RequestMapping(value={"/fileStorage/tree/create"},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileStorageCreate(@RequestBody JSONObject data) {
		System.out.println("controller.data-->>"+data.toJSONString());
		data = SecurityService.translateFun(data);
		return fileStorageService.newData(data);
	}

	@RequestMapping(value="/fileStorage/tree/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileStorageQuery(@RequestBody JSONObject data, HttpServletRequest request) {
		/*
		//获取访问路径
		String url = request.getRequestURI().replaceAll(request.getContextPath(), "").replaceAll("/query", "");
		//判断是否具有只查看自己的条件
		if("Y".equals(SecurityService.getDataAccessPerm(url))){
			data.put("userId", SecurityService.getCurrentPerson().getsID());
		}
		
		String enterpriseNo = SecurityService.getCurrentOgn().getsFID();
		data.put("enterpriseNo", enterpriseNo);
		*/
		
		data = SecurityService.addDataAccessPerm(data);
		return fileStorageService.queryData(data);
	}

	@RequestMapping(value="/fileStorage/tree/save",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileStorageSave(@RequestBody JSONObject object) {
		return fileStorageService.saveData(object);
	}
	
	@RequestMapping(value="/fileStorage/tree/delete",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileStorageDeletes(@RequestBody JSONObject data) {
		return fileStorageService.deleteData(data);
	}

	
	
	
	

	////////////////////////////////////////////////////////////
	
	
	
	

	@RequestMapping(value="/fileStorage/selectSingle",method=RequestMethod.GET)
	public ModelAndView fileStorageSelectSingle(){
	
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileStorage/selectSingle");
		return mav;
	}
	@RequestMapping(value="/fileStorage/list/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileStorageListQuery(@RequestBody JSONObject data, HttpServletRequest request) {
		data = SecurityService.addDataAccessPerm(data);
		return fileStorageService.queryData(data);
	}

	@RequestMapping(value="/fileStorage/selectList",method=RequestMethod.GET)
	public ModelAndView fileStorageSelectList(){
	
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileStorage/selectList");
		return mav;
	}
	
	//物料分类按会计
	@RequestMapping(value="/groupKJFL/tree",method=RequestMethod.GET)
	public ModelAndView groupKJFLTreeView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupKJFL/tree");
		return mav;
	}
	
	//重新排序
	@RequestMapping(value="/groupKJFL/sortView",method=RequestMethod.GET)
	public ModelAndView groupKJFLSortView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupKJFL/sort");
		return mav;
	}
	
	//移动
	@RequestMapping(value="/groupKJFL/moveView",method=RequestMethod.GET)
	public ModelAndView groupKJFLMoveView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupKJFL/move");
		return mav;
	}
	
	//选择物料分类（单选）
	@RequestMapping(value="/groupKJFL/selectSingle",method=RequestMethod.GET)
	public ModelAndView groupKJFLSelectSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupKJFL/selectSingle");
		return mav;
	}
	
	@RequestMapping(value={
			"/groupKJFL/tree/create",
			"/groupCKFL/tree/create",
			"/groupSPFL/tree/create"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject groupKJFLCreate(@RequestBody JSONObject data) {
		data = SecurityService.translateFun(data);
		JSONObject json = fileGroupService.newData(data);
		return json;
	}

	@RequestMapping(value= {
			"/groupKJFL/tree/query",
			"/groupCKFL/tree/query",
			"/groupSPFL/tree/query"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject groupKJFLQuery(@RequestBody JSONObject data) {
		data = SecurityService.addDataAccessPerm(data);
		return fileGroupService.queryData(data);
	}

	@RequestMapping(value= {
			"/groupKJFL/tree/save",
			"/groupCKFL/tree/save",
			"/groupSPFL/tree/save"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject groupKJFLSave(@RequestBody JSONObject object) {
		return fileGroupService.saveData(object);
	}
	
	@RequestMapping(value= {
			"/groupKJFL/tree/delete",
			"/groupCKFL/tree/delete",
			"/groupSPFL/tree/delete"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject groupKJFLDelete(@RequestBody JSONObject data) {
		return fileGroupService.deleteData(data);
	}

	
	@RequestMapping(value= {
			"/groupKJFL/tree/sort",
			"/groupCKFL/tree/sort",
			"/groupSPFL/tree/sort"
			},method=RequestMethod.POST)
	@ResponseBody
	public void groupKJFLSort(@RequestBody JSONObject data){
		String parentID = data.getString("parentID");
		JSONArray ids =  data.getJSONArray("ids");
		fileGroupService.sort(parentID, ids);
	}
	
	@RequestMapping(value= {
			"/groupKJFL/tree/move",
			"/groupCKFL/tree/move",
			"/groupSPFL/tree/move"
			},method=RequestMethod.POST)
	@ResponseBody
	public void groupKJFLMove(@RequestBody JSONObject data){
		String rowID = data.getString("rowID");
		String oldParentID = data.getString("oldParentID");
		String newParentID = data.getString("newParentID");
		fileGroupService.move(rowID, oldParentID, newParentID);
	}
	
	//物料分类按仓库
	@RequestMapping(value="/groupCKFL/tree",method=RequestMethod.GET)
	public ModelAndView groupCKFLTreeView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupCKFL/tree");
		return mav;
	}
	
	//重新排序
	@RequestMapping(value="/groupCKFL/sortView",method=RequestMethod.GET)
	public ModelAndView groupCKFLSortView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupCKFL/sort");
		return mav;
	}
	
	//移动
	@RequestMapping(value="/groupCKFL/moveView",method=RequestMethod.GET)
	public ModelAndView groupCKFLMoveView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupCKFL/move");
		return mav;
	}
	
	//选择物料分类（单选）
	@RequestMapping(value="/groupCKFL/selectSingle",method=RequestMethod.GET)
	public ModelAndView groupCKFLSelectSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupCKFL/selectSingle");
		return mav;
	}

	
	//物料分类按商品（销售）
	@RequestMapping(value="/groupSPFL/tree",method=RequestMethod.GET)
	public ModelAndView groupSPFLTreeView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupSPFL/tree");
		return mav;
	}
	
	//重新排序
	@RequestMapping(value="/groupSPFL/sortView",method=RequestMethod.GET)
	public ModelAndView groupSPFLSortView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupSPFL/sort");
		return mav;
	}
	
	//移动
	@RequestMapping(value="/groupSPFL/moveView",method=RequestMethod.GET)
	public ModelAndView groupSPFLMoveView(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupSPFL/move");
		return mav;
	}
	
	//选择物料分类（单选）
	@RequestMapping(value="/groupSPFL/selectSingle",method=RequestMethod.GET)
	public ModelAndView groupSPFLSelectSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/groupSPFL/selectSingle");
		return mav;
	}
	
	

	
	
	
	//物料档案
	@RequestMapping(value="/fileItem/list",method=RequestMethod.GET)
	public ModelAndView fileItemList(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileItem/list");
		return mav;
	}

	@RequestMapping(value="/fileItem/single",method=RequestMethod.GET)
	public ModelAndView fileItemSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileItem/single");
		return mav;
	}

	@RequestMapping(value="/fileItem/describe",method=RequestMethod.GET)
	public ModelAndView fileItemdescribe(){
	
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileItem/describe");
		return mav;
	}

	//物料档案（货号/条形码管理）
	@RequestMapping(value="/fileItem/barcode",method=RequestMethod.GET)
	public ModelAndView barcodeList(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileItem/barcode");
		return mav;
	}
	

	@RequestMapping(value="/fileItem/selectSingle",method=RequestMethod.GET)
	public ModelAndView fileItemSelectSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileItem/selectSingle");
		return mav;
	}

	@RequestMapping(value="/fileItem/selectMulti",method=RequestMethod.GET)
	public ModelAndView fileItemSelectMulti(){
	
		ModelAndView mav = new ModelAndView("/appcenter/inventory/fileItem/selectMulti");
		return mav;
	}

	
	
	//////////////////////BizData//////////////////////////////////////////
	@RequestMapping(value={"/fileItem/list/create"},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileItemCreate(@RequestBody JSONObject data) {
		data = SecurityService.translateFun(data);
		JSONObject json = fileItemService.newData(data);
		return json;
	}
	
	@RequestMapping(value="/fileItem/list/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileItemQuery(@RequestBody JSONObject data) {
		data = SecurityService.addDataAccessPerm(data);
		return fileItemService.queryData(data);
	}

	@RequestMapping(value="/fileItem/list/save",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileItemSave(@RequestBody JSONObject object) {
		return fileItemService.saveData(object);
	}

	@RequestMapping(value="/fileItem/list/delete",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileItemDeletes(@RequestBody JSONObject data) {
		//String userId = SecurityService.getCurrentPerson().getString("userId");
		return fileItemService.deleteData(data);
	}
	
	@RequestMapping(value={"/fileItem/list/createDetail"},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileItemCreateDetail(@RequestBody JSONObject data) {
		JSONObject json = fileItemService.newDataDetail(data);
		return json;
	}
	
	//设置安全库存
	@RequestMapping(value="/fileItem/list/queryDetail",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileItemQueryDetail(@RequestBody JSONObject data) {
		return fileItemService.queryDataDetail(data);
	}
	//////////////////////BizData//////////////////////////////////////////
	
	
	//根据输入的部分物料号过滤出前10行数据
	@RequestMapping(value="/fileItem/list/filterByNo",method=RequestMethod.GET)
	@ResponseBody
	public JSONObject fileItemFilterByNo(@RequestParam String likeNo) {
		JSONObject json = new JSONObject();
		if(SecurityService.getCurrentOgn()==null) {
			json.put("code", -1);
			json.put("msg", "未登录！");
			return json;
		}
		String enterpriseNo = SecurityService.getCurrentOgn().getsFID();
		List<FileItem> list = fileItemService.filterByNo(likeNo, enterpriseNo);
		json.put("code", 0);
		json.put("data", list);
		return json;
	}
		
	
	
	
	@RequestMapping(value="/storageItem/list/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject storageItemQuery(@RequestBody JSONObject data) {
		return storageItemService.queryData(data);
	}
	
	@RequestMapping(value="/fileItem/list/getMaxSortNoPlus",method=RequestMethod.GET)
	@ResponseBody
	public JSONObject getMaxSortNoPlus(@RequestParam(value="enterpriseNo",required=true) String enterpriseNo) {
		String sortNo = fileItemService.getMaxSortNoPlus(enterpriseNo);
		JSONObject json = new JSONObject();
		json.put("sortNo", sortNo);
		return json;
	}

	@RequestMapping(value="/fileItem/list/insert",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject fileItemInsert(@RequestBody JSONObject data){
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");

		String enterpriseNo = SecurityService.getCurrentOgn().getsFID();
		String enterpriseName = SecurityService.getCurrentOgn().getsLongName();
		
		JSONArray jsonArray = data.getJSONArray("items");
		int count = jsonArray.size();
		int ignore = 0;
		for(int i=0;i<count;i++){
			JSONObject json = jsonArray.getJSONObject(i);
			String itemNo = json.getString("itemNo");
			String itemName = json.getString("itemName");
			String itemProperty = json.getString("itemProperty");
			String unitName = json.getString("unitName");
			if(fileItemService.getByNo(itemNo, enterpriseNo)==null){
				//不存在
				fileItemService.insert(itemNo, itemName, itemProperty, unitName, cUsercode, cUsername, userId, enterpriseNo, enterpriseName);
			}else{
				//已经存在
				ignore++;
			}
		}
		
		int ok = count-ignore;
		JSONObject json = new JSONObject();
		json.put("result", "共"+count+"种物料，"+"完成导入"+ ok +"种，已经存在"+ignore+"种！");
		
		return json;		
	}

	@RequestMapping(value="/fileItem/list/alterStorage",method=RequestMethod.POST)
	@ResponseBody
	public int alterStorage(@RequestBody JSONObject data){
		String storageID = data.getString("storageID");
		JSONArray ids = data.getJSONArray("ids");
		for(int i=0;i<ids.size();i++){
			String id = ids.getString(i);
			fileItemService.updateStorage(id, storageID);
		}
		return 0;
	}

	/*
	@RequestMapping(value="/fileItem/list/export",method=RequestMethod.GET)
	public void FileItemExport(HttpServletResponse response){

        //模拟从数据库获取需要导出的数据
//		List<Person> personList = new ArrayList<>();
//		Person person1 = new Person("路飞","1",new Date());
//		Person person2 = new Person("娜美","2", DateUtils.addDate(new Date(),3));
//		Person person3 = new Person("索隆","1", DateUtils.addDate(new Date(),10));
//		Person person4 = new Person("小狸猫","1", DateUtils.addDate(new Date(),-10));
//		personList.add(person1);
//		personList.add(person2);
//		personList.add(person3);
//		personList.add(person4);

		List<FileItem> fileItemList = fileItemService.getAll();
        //导出操作
//		FileUtil.exportExcel(personList,"花名册","草帽一伙",Person.class,"海贼王.xls",response);
		FileEasypoiUtil.exportExcel(fileItemList,"花名册","草帽一伙",FileItem.class,"海贼王.xls",response);
    }
	*/

	@RequestMapping(value="/itemBatch/list",method=RequestMethod.GET)
	public ModelAndView itemBatchList(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/itemBatch/list");
		return mav;
	}

	@RequestMapping(value="/itemBatch/single",method=RequestMethod.GET)
	public ModelAndView itemBatchSingle(){
	
		ModelAndView mav = new ModelAndView("/appcenter/inventory/itemBatch/single");
		return mav;
	}

	@RequestMapping(value="/itemBatch/selectSingle",method=RequestMethod.GET)
	public ModelAndView itemBatchSelectSingle(){
	
		ModelAndView mav = new ModelAndView("/appcenter/inventory/itemBatch/selectSingle");
		return mav;
	}


	@RequestMapping(value={"/itemBatch/list/create"},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject itemBatchCreate(@RequestBody JSONObject data) {
		data = SecurityService.translateFun(data);
		JSONObject json = itemBatchService.newData(data);
		return json;
	}

	@RequestMapping(value="/itemBatch/list/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject itemBatchQuery(@RequestBody JSONObject data) {
		data = SecurityService.addDataAccessPerm(data);
		return itemBatchService.queryData(data);
	}

	@RequestMapping(value="/itemBatch/list/save",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject itemBatchSave(@RequestBody JSONObject object) {
		return itemBatchService.saveData(object);
	}

	@RequestMapping(value="/itemBatch/list/delete",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject itemBatchDeletes(@RequestBody JSONObject data) {
		return itemBatchService.deleteData(data);
	}
	

	
	
	
	//////////////////////////////////////////////////////////////////////////////////////
	
	@RequestMapping(value={"/invCBKZ/single"},method=RequestMethod.GET)
	public ModelAndView invCBKZSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/invCBKZ/single");
		mav.addObject("path", "/inventory/invCBKZ/single");
		return mav;
	}

	//////////////////////////////////////////////////////////////////////////////////////

	//////////////////////////////////////////////////////////////////////////////////////
	@RequestMapping(value={
			"/invCBKZ/single/query"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invCBKZQuery(@RequestBody JSONObject data) {
		data = SecurityService.addDataAccessPerm(data);
		return storageLedgerService.queryData(data);
	}

	@RequestMapping(value={
			"/invCBKZ/single/save"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invCBKZSave(@RequestBody JSONObject object) {
		return storageLedgerService.saveData(object);
	}

	@RequestMapping(value={
			"/invCBKZ/single/delete"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invCBKZDelete(@RequestBody JSONObject data) {
		return storageLedgerService.deleteData(data);
	}

	@RequestMapping(value={
			"/invCBKZ/single/create"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invCBKZCreate(@RequestBody JSONObject data, HttpServletRequest request) {
		data = SecurityService.translateFun(data);
		return storageLedgerService.newData(data);
	}

	@RequestMapping(value={
			"/invCBKZ/single/createDetail"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invCBKZCreateDetail(@RequestBody JSONObject data, HttpServletRequest request) {
		return storageLedgerService.newDataDetail(data);
	}

	@RequestMapping(value={
			"/invCBKZ/single/queryDetail"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invCBKZQueryDetail(@RequestBody JSONObject data) {
		return storageLedgerService.queryDataDetail(data);
	}
	//////////////////////////////////////////////////////////////////////////////////////

	

	
	//////////////////////////////////////////////////////////////////////////////////////
	@RequestMapping(value={
			"/invCBKZ/single/confirm"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invCBKZConfirm(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();
		
		return inventoryService.storageLedgerConfirm(id, cUsercode, cUsername, userId, employeeNo, employeeName);
	}

	@RequestMapping(value={
			"/invCBKZ/single/active"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invCBKZActive(@RequestBody JSONObject data) {
		String id = data.getString("id");
		return inventoryService.storageLedgerActive(id);
	}
	
	@RequestMapping(value={
			"/invCBKZ/single/agreeIt"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invCBKZAgreeIt(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();

		return inventoryService.storageLedgerAgreeIt(id, cUsercode, cUsername, userId, employeeNo, employeeName);
	}

	@RequestMapping(value={
			"/invCBKZ/single/unAgree"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invCBKZUnAgree(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();

		return inventoryService.storageLedgerUnAgree(id, cUsercode, cUsername, userId, employeeNo, employeeName);
	}
	
	@RequestMapping(value={
			"/invCBKZ/single/close"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invCBKZClose(@RequestBody JSONObject data) {
		String id = data.getString("id");
		return inventoryService.storageLedgerClose(id);
	}

	@RequestMapping(value={
			"/invCBKZ/single/open"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invCBKZOpen(@RequestBody JSONObject data) {
		String id = data.getString("id");
		return inventoryService.storageLedgerOpen(id);
	}

	
	
	
	
	@RequestMapping(value={"/invDBDJ/single"},method=RequestMethod.GET)
	public ModelAndView invDBDJSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/invDBDJ/single");
		mav.addObject("path", "/inventory/invDBDJ/single");
		return mav;
	}
	
	@RequestMapping(value="/invQTRK/single",method=RequestMethod.GET)
	public ModelAndView invQTRKSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/invQTRK/single");
		mav.addObject("path", "/inventory/invQTRK/single");
		return mav;
	}
	
	@RequestMapping(value="/invQTCK/single",method=RequestMethod.GET)
	public ModelAndView invQTCKSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/invQTCK/single");
		mav.addObject("path", "/inventory/invQTCK/single");
		return mav;
	}
	
	@RequestMapping(value={"/invPDDJ/single"},method=RequestMethod.GET)
	public ModelAndView invPDDJSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/invPDDJ/single");
		mav.addObject("path", "/inventory/invPDDJ/single");
		return mav;
	}
	
	@RequestMapping(value={"/invBFDJ/single"},method=RequestMethod.GET)
	public ModelAndView invBFDJSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/invBFDJ/single");
		mav.addObject("path", "/inventory/invBFDJ/single");
		return mav;
	}
	
	@RequestMapping(value={"/invXHCK/single"},method=RequestMethod.GET)
	public ModelAndView invXHCKSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/invXHCK/single");
		mav.addObject("path", "/inventory/invXHCK/single");
		return mav;
	}
	
	@RequestMapping(value={"/invJCJR/single"},method=RequestMethod.GET)
	public ModelAndView invJCJRSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/invJCJR/single");
		mav.addObject("path", "/inventory/invJCJR/single");
		return mav;
	}
	
	@RequestMapping(value={"/invCRGH/single"},method=RequestMethod.GET)
	public ModelAndView invCRGHSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/invCRGH/single");
		mav.addObject("path", "/inventory/invCRGH/single");
		return mav;
	}

	//////////////////////////////////////////////////////////////////////////////////////
	@RequestMapping(value={
			"/invDBDJ/single/query"
			,"/invJCJR/single/query"
			,"/invCRGH/single/query"
			,"/invPDDJ/single/query"
			,"/invBFDJ/single/query"
			,"/invXHCK/single/query"
			
			,"/invQTRK/single/query"
			,"/invQTCK/single/query"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invDBDJQuery(@RequestBody JSONObject data) {
		data = SecurityService.addDataAccessPerm(data);
		return storageRecordService.queryData(data);
	}

	@RequestMapping(value={
			"/invDBDJ/single/save"
			,"/invJCJR/single/save"
			,"/invCRGH/single/save"
			,"/invPDDJ/single/save"
			,"/invBFDJ/single/save"
			,"/invXHCK/single/save"
			
			,"/invQTRK/single/save"
			,"/invQTCK/single/save"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invDBDJSave(@RequestBody JSONObject object) {
		return storageRecordService.saveData(object);
	}

	@RequestMapping(value={
			"/invDBDJ/single/delete"
			,"/invJCJR/single/delete"
			,"/invCRGH/single/delete"
			,"/invPDDJ/single/delete"
			,"/invBFDJ/single/delete"
			,"/invXHCK/single/delete"
			
			,"/invQTRK/single/delete"
			,"/invQTCK/single/delete"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invDBDJDelete(@RequestBody JSONObject data) {
		return storageRecordService.deleteData(data);
	}

	@RequestMapping(value={
			"/invDBDJ/single/create"
			,"/invJCJR/single/create"
			,"/invCRGH/single/create"
			,"/invPDDJ/single/create"
			,"/invBFDJ/single/create"
			,"/invXHCK/single/create"
			
			,"/invQTRK/single/create"
			,"/invQTCK/single/create"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invDBDJCreate(@RequestBody JSONObject data, HttpServletRequest request) {
		data = SecurityService.translateFun(data);
		return storageRecordService.newData(data);
	}

	@RequestMapping(value={
			"/invDBDJ/single/createDetail"
			,"/invJCJR/single/createDetail"
			,"/invCRGH/single/createDetail"
			,"/invPDDJ/single/createDetail"
			,"/invBFDJ/single/createDetail"
			,"/invXHCK/single/createDetail"
			
			,"/invQTRK/single/createDetail"
			,"/invQTCK/single/createDetail"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invDBDJCreateDetail(@RequestBody JSONObject data, HttpServletRequest request) {
		return storageRecordService.newDataDetail(data);
	}

	@RequestMapping(value={
			"/invDBDJ/single/queryDetail"
			,"/invJCJR/single/queryDetail"
			,"/invCRGH/single/queryDetail"
			,"/invPDDJ/single/queryDetail"
			,"/invBFDJ/single/queryDetail"
			,"/invXHCK/single/queryDetail"
			
			,"/invQTRK/single/queryDetail"
			,"/invQTCK/single/queryDetail"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject invDBDJQueryDetail(@RequestBody JSONObject data) {
		return storageRecordService.queryDataDetail(data);
	}
	//////////////////////////////////////////////////////////////////////////////////////

	

	
	//////////////////////////////////////////////////////////////////////////////////////
	@RequestMapping(value={
			"/invDBDJ/single/confirm"
			,"/invJCJR/single/confirm"
			,"/invCRGH/single/confirm"
			,"/invPDDJ/single/confirm"
			,"/invBFDJ/single/confirm"
			,"/invXHCK/single/confirm"
			
			,"/invQTRK/single/confirm"
			,"/invQTCK/single/confirm"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invDBDJConfirm(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();
		
		return inventoryService.storageRecordConfirm(id, cUsercode, cUsername, userId, employeeNo, employeeName);
	}

	@RequestMapping(value={
			"/invDBDJ/single/active"
			,"/invJCJR/single/active"
			,"/invCRGH/single/active"
			,"/invPDDJ/single/active"
			,"/invBFDJ/single/active"
			,"/invXHCK/single/active"
			
			,"/invQTRK/single/active"
			,"/invQTCK/single/active"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invDBDJActive(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();

		return inventoryService.storageRecordActive(id, cUsercode, cUsername, userId, employeeNo, employeeName);
	}
	
	@RequestMapping(value={
			"/invDBDJ/single/agreeIt"
			,"/invJCJR/single/agreeIt"
			,"/invCRGH/single/agreeIt"
			,"/invPDDJ/single/agreeIt"
			,"/invBFDJ/single/agreeIt"
			,"/invXHCK/single/agreeIt"
			
			,"/invQTRK/single/agreeIt"
			,"/invQTCK/single/agreeIt"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invDBDJAgreeIt(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();

		return inventoryService.storageRecordAgreeIt(id, cUsercode, cUsername, userId, employeeNo, employeeName);
	}

	@RequestMapping(value={
			"/invDBDJ/single/unAgree"
			,"/invJCJR/single/unAgree"
			,"/invCRGH/single/unAgree"
			,"/invPDDJ/single/unAgree"
			,"/invBFDJ/single/unAgree"
			,"/invXHCK/single/unAgree"
			
			,"/invQTRK/single/unAgree"
			,"/invQTCK/single/unAgree"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invDBDJUnAgree(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();
		return inventoryService.storageRecordUnAgree(id, cUsercode, cUsername, userId, employeeNo, employeeName);
	}
	
	@RequestMapping(value={
			"/invDBDJ/single/close"
			,"/invJCJR/single/close"
			,"/invCRGH/single/close"
			,"/invPDDJ/single/close"
			,"/invBFDJ/single/close"
			,"/invXHCK/single/close"
			
			,"/invQTRK/single/close"
			,"/invQTCK/single/close"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invDBDJClose(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();
		return inventoryService.storageRecordClose(id, cUsercode, cUsername, userId, employeeNo, employeeName);
	}

	@RequestMapping(value={
			"/invDBDJ/single/open"
			,"/invJCJR/single/open"
			,"/invCRGH/single/open"
			,"/invPDDJ/single/open"
			,"/invBFDJ/single/open"
			,"/invXHCK/single/open"
			
			,"/invQTRK/single/open"
			,"/invQTCK/single/open"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> invDBDJOpen(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();
		return inventoryService.storageRecordOpen(id, cUsercode, cUsername, userId, employeeNo, employeeName);
	}

	//盘点单打印
	@RequestMapping(value={
			"/invPDDJ/single/printPDF"
			},method=RequestMethod.GET)
	@ResponseBody
	public void invPDDJPrintPDF(@RequestParam(value="id",required=true) String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//inventoryService.invPDDJPrintPDF(id, response);
	    Document doc = new Document();// 创建一个PDF文档，我们的PDF内容都写在上面
	    response.setContentType("application/pdf");
//	    PdfWriter writer = PdfWriter.getInstance(doc, response.getOutputStream());
	    PdfWriter.getInstance(doc, response.getOutputStream());
	    //打开doc
	    doc.open();
	    //填写doc内容
	    inventoryService.invPDDJPrintPDF(id,doc);
		//关闭doc
	    doc.close();
	}

	//调拨单打印
	@RequestMapping(value={
			"/invDBDJ/single/printPDF"
			,"/invBFDJ/single/printPDF"
			},method=RequestMethod.GET)
	@ResponseBody
	public void invDBDJPrintPDF(@RequestParam(value="id",required=true) String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//inventoryService.invDBDJPrintPDF(id, response);
	    Document doc = new Document();// 创建一个PDF文档，我们的PDF内容都写在上面
	    response.setContentType("application/pdf");
//	    PdfWriter writer = PdfWriter.getInstance(doc, response.getOutputStream());
	    PdfWriter.getInstance(doc, response.getOutputStream());
	    //打开doc
	    doc.open();
	    //填写doc内容
	    inventoryService.invDBDJPrintPDF(id,doc);
		//关闭doc
	    doc.close();
	}

	//////////////////////////////////////////////////////////////////////////////////////
	

	//其他出入库单打印
	@RequestMapping(value={
			"/invQTRK/single/printPDF"
			,"/invQTCK/single/printPDF"
			,"/invCBKZ/single/printPDF"
			,"/invXHCK/single/printPDF"
			},method=RequestMethod.GET)
	@ResponseBody
	public void invQTRKPrintPDF(@RequestParam(value="id",required=true) String id, HttpServletRequest request, HttpServletResponse response) throws Exception {
		//inventoryService.invQTRKPrintPDF(id, response);
	    Document doc = new Document();// 创建一个PDF文档，我们的PDF内容都写在上面
	    response.setContentType("application/pdf");
//	    PdfWriter writer = PdfWriter.getInstance(doc, response.getOutputStream());
	    PdfWriter.getInstance(doc, response.getOutputStream());
	    //打开doc
	    doc.open();
	    //填写doc内容
	    inventoryService.invQTRKPrintPDF(id,doc);
		//关闭doc
	    doc.close();
	}

	//////////////////////////////////////////////////////////////////////////////////////

	
	
	//盘点料件清单
	@RequestMapping(value="/stocktaking/single",method=RequestMethod.GET)
	public ModelAndView stocktakingSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/stocktaking/single");
		mav.addObject("path", "/inventory/stocktaking/single");
		return mav;
	}

	@RequestMapping(value={
			"/stocktaking/single/query"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject stocktakingQuery(HttpServletRequest request, @RequestBody JSONObject data) {
		data = SecurityService.addDataAccessPerm(data);
		return stocktakingService.queryData(data);
	}

	@RequestMapping(value={
			"/stocktaking/single/save"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject stocktakingSave(@RequestBody JSONObject object) {
		return stocktakingService.saveData(object);
		
	}

	@RequestMapping(value={
			"/stocktaking/single/delete"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject stocktakingDelete(@RequestBody JSONObject data) {
		return stocktakingService.deleteData(data);
	}

	@RequestMapping(value={
			"/stocktaking/single/create"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject stocktakingCreate(@RequestBody JSONObject data) {
		System.out.println("controller.data-->>"+data.toJSONString());
		JSONObject params = JSONObject.parseObject(data.toJSONString());
		//增加登录信息
		//缺省值
		JSONArray defaultValues = params.getJSONArray("defaultValues");
		//循环缺省值（多行）
		for(int i=0;i<defaultValues.size();i++) {
			JSONObject rowValue = defaultValues.getJSONObject(i);
			//循环列
			//循环缺省值（单行）
			for(String col: rowValue.keySet()) {
				System.out.println("controller.defaultValues-->>"+col+":"+rowValue.get(col));
				if(":getCurrentDate()".equals(rowValue.get(col))) {
					rowValue.put(col, Utils.getCurrentDate());
				}
				if(":getCurrentPsmFID()".equals(rowValue.get(col))) {
					rowValue.put(col, SecurityService.getCurrentPsm().getsFID());
				}
				if(":getCurrentPsmFName()".equals(rowValue.get(col))) {
					rowValue.put(col, SecurityService.getCurrentPsm().getsFName());
				}
				if(":getCurrentDateTime()".equals(rowValue.get(col))) {
					rowValue.put(col, Utils.getCurrentDateTime());
				}
				if(":getCurrentPersonCode()".equals(rowValue.get(col))) {
					rowValue.put(col, SecurityService.getCurrentPerson().getString("cUsercode"));
				}
				if(":getCurrentPersonName()".equals(rowValue.get(col))) {
					rowValue.put(col, SecurityService.getCurrentPerson().getString("cUsername"));
				}
				if(":getCurrentPersonID()".equals(rowValue.get(col))) {
					rowValue.put(col, SecurityService.getCurrentPerson().getString("userId"));
				}
				if(":getCurrentOgnFID()".equals(rowValue.get(col))) {
					rowValue.put(col, SecurityService.getCurrentOgn().getsFID());
				}
				if(":getCurrentOgnLongName()".equals(rowValue.get(col))) {
					rowValue.put(col, SecurityService.getCurrentOgn().getsLongName());
				}
				System.out.println("controller.defaultValues-->>"+col+":"+rowValue.get(col));
			}
			
		}
		return stocktakingService.newData(params);
	}


	@RequestMapping(value={
			"/stocktaking/single/createDetail"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject stocktakingCreateDetail(@RequestBody JSONObject data) {
		JSONObject json = stocktakingService.newDataDetail(data);
		return json;
	}

	@RequestMapping(value={
			"/stocktaking/single/queryDetail"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject stocktakingQueryDetail(@RequestBody JSONObject data) {
		return stocktakingService.queryDataDetail(data);
	}
	


	
	//////////////////////////////////////////////////////////////////////////////////////
	@RequestMapping(value={
			"/stocktaking/single/confirm"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> stocktakingConfirm(@RequestBody JSONObject data) {
		String id = data.getString("id");
		return inventoryService.stocktakingConfirm(id);
	}


	@RequestMapping(value={
			"/stocktaking/single/active"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> stocktakingActive(@RequestBody JSONObject data) {
		String id = data.getString("id");
		return inventoryService.stocktakingActive(id);
	}
	
	@RequestMapping(value={
			"/stocktaking/single/agreeIt"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> stocktakingAgreeIt(@RequestBody JSONObject data) {
		String id = data.getString("id");
		
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		
		return inventoryService.stocktakingAgreeIt(id, cUsercode, cUsername, userId);
	}
	
	@RequestMapping(value={
			"/stocktaking/single/unAgree"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> stocktakingUnAgree(@RequestBody JSONObject data) {
		String id = data.getString("id");
		return inventoryService.stocktakingUnAgree(id);
	}
	
	@RequestMapping(value={
			"/stocktaking/single/close"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> stocktakingClose(@RequestBody JSONObject data) {
		String id = data.getString("id");
		return inventoryService.stocktakingClose(id);
	}

	@RequestMapping(value={
			"/stocktaking/single/open"
			},method=RequestMethod.POST)
	@ResponseBody
	public Map<String,Object> stocktakingOpen(@RequestBody JSONObject data) {
		String id = data.getString("id");
		return inventoryService.stocktakingOpen(id);
	}
	
	//生成盘点清单
	@RequestMapping(value="/stocktaking/generate",method=RequestMethod.GET)
	public ModelAndView stocktakingGenerate(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/stocktaking/generate");
		return mav;
	}
	
	//生成盘点清单
	@RequestMapping(value="/stocktaking/generate/start",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject stocktakingGenerate(@RequestBody JSONObject data) {
		String documentNo = data.getString("documentNo");
		int method = data.getIntValue("method");
		String cUsercode = SecurityService.getCurrentPerson().getString("cUsercode");
		String cUsername = SecurityService.getCurrentPerson().getString("cUsername");
		String userId = SecurityService.getCurrentPerson().getString("userId");
		String enterpriseNo = SecurityService.getCurrentOgn().getsFID();
		String enterpriseName = SecurityService.getCurrentOgn().getsLongName();
		return inventoryService.stocktakingGenerate(documentNo, method, cUsercode, cUsername, userId, enterpriseNo, enterpriseName);
	}
	
	//补入实盘数量
	@RequestMapping(value="/stocktakingDetail/list",method=RequestMethod.GET)
	public ModelAndView stocktakingDetailList(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/stocktakingDetail/list");
		mav.addObject("path", "/inventory/stocktakingDetail/single");
		return mav;
	}
	@RequestMapping(value="/stocktakingDetail/single",method=RequestMethod.GET)
	public ModelAndView stocktakingDetailSingle(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/stocktakingDetail/single");
		return mav;
	}

	@RequestMapping(value={
			"/stocktakingDetail/list/query"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject stocktakingDetailQuery(HttpServletRequest request, @RequestBody JSONObject data) {
		data = SecurityService.addDataAccessPerm(data);
		return stocktakingDetailService.queryData(data);
	}

	@RequestMapping(value={
			"/stocktakingDetail/list/save"
			},method=RequestMethod.POST)
	@ResponseBody
	public JSONObject stocktakingDetailSave(@RequestBody JSONObject object) {
		return stocktakingDetailService.saveData(object);
		
	}

	
	
	
	
	
	
	
	

	
	@RequestMapping(value="/recordDetailQuery/list",method=RequestMethod.GET)
	public ModelAndView recordDetailQueryList(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/recordDetailQuery/list");
		return mav;
	}

	@RequestMapping(value="/recordDetailQuery/list/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject recordDetailQuery(@RequestBody JSONObject data,HttpServletRequest request) {
		data = SecurityService.addDataAccessPerm(data);
		return storageRecordService.queryDataDetail(data);
	}

	
	
	//库存明细表
	@RequestMapping(value="/storageItemQuery/list",method=RequestMethod.GET)
	public ModelAndView storageItemQueryList(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/storageItemQuery/list");
		return mav;
	}
	
	//库存明细表-按库位显示
	@RequestMapping(value="/storageItemQuery/list/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject storageItemQueryQuery(@RequestBody JSONObject data) {
		data = SecurityService.addDataAccessPerm(data);
		return storageItemService.queryData(data);
	}
	
	@RequestMapping(value="/storageItemBatchQuery/list",method=RequestMethod.GET)
	public ModelAndView storageItemBatchQueryList(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/storageItemBatchQuery/list");
		return mav;
	}

	//批号库存明细表
	@RequestMapping(value="/storageItemBatchQuery/list/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject storageItemBactchQuery(@RequestBody JSONObject data) {
		data = SecurityService.addDataAccessPerm(data);
		return storageItemBatchService.queryData(data);
	}
	
	
	
	//用于退库选择使用
	@RequestMapping(value="/recordDetailSelect/selectMulti",method=RequestMethod.GET)
	public ModelAndView recordDetailSelectMultip(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/recordDetailSelect/selectMulti");
		return mav;
	}

	
	//选择生产入库单、委外进货单、采购进货单、工艺入库单和销售退货单，用于质量检验
	@RequestMapping(value="/recordDetailQualitySelect/selectSingle",method=RequestMethod.GET)
	public ModelAndView recordDetailQualitySelect(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/recordDetailQualitySelect/selectSingle");
		return mav;
	}
	
	//用于开具发票
	//打开多选对话框（选择销售出入库、采购、委外进退货）
	@RequestMapping(value="/recordDetailInvoiceSelect/selectMulti",method=RequestMethod.GET)
	public ModelAndView recordDetailInvoiceSelectMultip(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/recordDetailInvoiceSelect/selectMulti");
		return mav;
	}
	
	//用于工艺入库的退库使用
	//打开多选对话框（选择工艺入库单）
	@RequestMapping(value="/recordDetailInvgyrkSelect/selectMulti",method=RequestMethod.GET)
	public ModelAndView recordDetailInvgyrkSelectMultip(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/recordDetailInvgyrkSelect/selectMulti");
		return mav;
	}

	//选择借出/入单
	@RequestMapping(value="/recordDetailInvjcjr/list/query",method=RequestMethod.POST)
	@ResponseBody
	public JSONObject recordDetailInvjcjrQuery(@RequestBody JSONObject data,HttpServletRequest request) {
		
		//获取访问路径
		String url = request.getRequestURI().replaceAll(request.getContextPath(), "").replaceAll("/query", "");
		//判断是否具有只查看自己的条件
		if("Y".equals(SecurityService.getDataAccessPerm(url))){
			data.put("userId", SecurityService.getCurrentPerson().getString("userId"));
		}
		
		String enterpriseNo = SecurityService.getCurrentOgn().getsFID();
		data.put("enterpriseNo", enterpriseNo);

		return storageRecordDetailService.queryJCJR(data);
	}
	
	//选择借出/入单
	@RequestMapping(value={"/recordDetailInvjcjrSelect/selectMulti"},method=RequestMethod.GET)
	public ModelAndView recordDetailInvjcjrSelectMulti(){
		ModelAndView mav = new ModelAndView("/appcenter/inventory/recordDetailInvjcjrSelect/selectMulti");
		mav.addObject("path", "/inventory/recordDetailInvjcjrSelect/selectMulti");
		return mav;
	}

	
	
	/*
	//退库通用函数
	@RequestMapping(value={
			"/pushXSRK"
			,"/pushCGCK"
			,"/pushSCCK"
			,"/pushWWCK"
			,"/pushFLRK"
			},method=RequestMethod.POST)

	//由销售发货单生成销售退货单
	//@RequestMapping(value = "/pushXSRK", method = RequestMethod.POST)
	@ResponseBody
	public JSONObject pushBACK(@RequestBody JSONObject params){
		String id = params.getString("id");
		
		//填写销售发货单
		StorageRecord storageRecord = storageRecordService.getByID(id);
		
		String cUsercode = SecurityService.getCurrentPerson().getsCode();
		String cUsername = SecurityService.getCurrentPerson().getsName();
		String userId = SecurityService.getCurrentPerson().getsID();
		
		String autoState = "N";
		String flowType = "1";
		String autoPayment = "N";//现结
		
		String employeeNo = SecurityService.getCurrentPsm().getsFID();
		String employeeName = SecurityService.getCurrentPsm().getsFName();

		//填写销售发货单
		StorageRecord obj = inventoryService.storageRecordBACKInsert(storageRecord, cUsercode, cUsername, userId, autoState, flowType, autoPayment, employeeNo, employeeName);

		MapMessage mapMessage = null;
		
		if(obj==null){
//			JSONObject json = new JSONObject();
//			json.put("code", -1);
//			json.put("status", "生成单据失败");
//			return json;
			
			mapMessage = new MapMessage(null,null,null,null
					,MapMessage.STATUSINFO_FAILURE_CODE//"http://www.iune.cn"
					,MapMessage.STATUSINFO_FAILURE_MSG//"操作成功！"
					,MapMessage.STATUSINFO_FAILURE_INFO//"操作成功！"
					,MapMessage.STATUSINFO_FAILURE_FLAG//"success"
					);			
			return mapMessage.toJSONObject();
		}
		
//		JSONObject json = new JSONObject();
//		json.put("code", 0);
//		json.put("status", "成功");
//		json.put("id", accountPayment.getfID());
//		json.put("billNo", accountPayment.getAccountPaymentNo());
//		return json;
		
		mapMessage = new MapMessage(obj.getfID(),obj.getRecordNo(),obj.getBillType(),obj.getBillTypeName()
				,MapMessage.STATUSINFO_SUCCESS_CODE//"http://www.iune.cn"
				,MapMessage.STATUSINFO_SUCCESS_MSG//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_INFO//"操作成功！"
				,MapMessage.STATUSINFO_SUCCESS_FLAG//"success"
				);
		
		SysInfo sysInfo = sysInfoService.getByID(obj.getSystemCode());
		if(sysInfo!=null){
			mapMessage.setAppID(sysInfo.getfID());
			mapMessage.setsProcess(sysInfo.getAbsoluteUrl());
			mapMessage.setsName(sysInfo.getSystemName());
		}

		return mapMessage.toJSONObject();
		
	}
	*/

	/*
	//库存金额
	@RequestMapping(value="/storageItem/getCostingAmount",method=RequestMethod.GET)
	@ResponseBody
	public BigDecimal getCostingAmount()  {
		return storageItemService.getCostingAmount();
	}

	//库存数量
	@RequestMapping(value="/storageItem/getQuantityL",method=RequestMethod.GET)
	@ResponseBody
	public BigDecimal getQuantityL()  {
		return storageItemService.getQuantityL();
	}
	*/
	
	
	//////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////
	//////////////////////////////////////////////////////////////
	

}
